#ifndef _FONTFACEHANDLE_H_
#define _FONTFACEHANDLE_H_

namespace Font
{

	// common 
	// lineHeight=24 
	// base=19 
	// scaleW=256 
	// scaleH=256 
	// pages=1 
	// packed=0 
	// alphaChnl=1 
	// redChnl=0 
	// greenChnl=0 
	// blueChnl=0

	class Glyph;
	class GlyphPage;
	class GlyphMap;
	class Text;
	class TextInstructions;

	class FaceHandle
	{
	
	public:
	
		FaceHandle(Library* a_Library, Family* a_Owner);
		~FaceHandle();

		void SetMetrics(Metrics* a_Metrics);
		void SetFontSize(unsigned int a_FontSize, unsigned int a_LineHeight);

		Family* GetFamily();

		void SetGlyphRange(unsigned int a_RangeStart, unsigned int a_RangeEnd);
		void SetGlyphTotal(unsigned int a_Count);
		Glyph* GetNextGlyph();
		Glyph* GetNextGlyph(unsigned int a_Index);
		Glyph* GetGlyph(wchar_t a_Character);
		GlyphMap* GetGlyphMap();

		void SetKerningTable(KerningTable* a_Table);
		KerningTable* GetKerningTable();
		int GetKerning(wchar_t a_Left, wchar_t a_Right);

		void SetCharMap(CharMap* a_Map);

		unsigned int GetHeightNewLine();
		unsigned int GetWidthSpace();

		void SetPaging(bool a_State, unsigned int a_MinimumLevel);

		tb::Pos2 GetMessageDimensions(const tb::StringBase<wchar_t>& a_Message);

		Text* CreateText(const wchar_t* a_Message);
		Text* CreateText(TextInstructions* a_Instructions);
	
	protected:

		void _WriteGlyph(GLbyte* a_Target, unsigned int a_OffsetX, unsigned int a_OffsetY, Glyph* a_Source);

		Family* m_Owner;
		Metrics* m_Metrics;
		KerningTable* m_Kerning;
		CharMap* m_Map;
		GlyphMap* m_GlyphMap;
		bool m_Paging;
		unsigned int m_PagingMinimumLevel;

		int m_Size, m_SizeReal;
		int m_AdvanceVertical;

		unsigned int m_HeightLine;
		unsigned int m_HeightBase;

		Face* m_Parent;
		std::vector<Text*> m_DisplayLists;

		Glyph** m_Glyph;
		Glyph* m_GlyphDefault;
		unsigned int m_GlyphNextIndex;
		unsigned int m_GlyphFilled;
		unsigned int m_GlyphTotal;

		GlyphPage* m_Texture;

		Library* m_Library;
	
	}; // class FontFaceHandle

}; // namespace Rpt
	
#endif